import sys
sys.path.append('../')
from common.config import *
from db.mysql import MysqlClient
from itertools import product
from common.helper import Helper


class Spider(object):
    def __init__(self):
        self.mysql = MysqlClient()
        self.name = "幼儿医疗健康保险（传染病）"
    # 生成产品数据
    def genProductInfo(self):
        plan = {
            #年龄段
            "year":[str( i ) for i in range(0,18)],
            # 有无社保
            "socialSec":["Y","N"],
            #传染病门诊医疗
            "contagionMedical":["100000"],
            #特定传染病住院医疗
            "specialContagion":["50000"],
            #意外门诊急诊社会医疗保险
            "accidentOutpatient":["10000"],
            #意外住院津贴
            "accidentAllowance":["10000"],
            #意外食物中毒
            "foodPoison":["100000"],
            #意外身故
            "accidentDeath":["100000"]
        }

        for v in product(plan["year"],plan["socialSec"],plan["contagionMedical"],plan["specialContagion"],plan["accidentOutpatient"],plan["accidentAllowance"],plan["foodPoison"],plan["accidentDeath"]):
            data = Helper.formatProductInfo( plan,v )
            self.mysql.cursor.execute(domain[self.name]["insert_sql"].format( **data ))
            self.mysql._conn.commit()
            print( domain[self.name]["insert_sql"].format( **data ) )
